Skip to content

fix: accept quoted numeric strings in OrganizationCostsResult.Amount.value() (#769)#771

Open
kuntal1461 wants to merge 1 commit into
openai:mainfrom
kuntal1461:fix/issue-769-amount-value
Open

fix: accept quoted numeric strings in OrganizationCostsResult.Amount.value() (#769)#771
kuntal1461 wants to merge 1 commit into
openai:mainfrom
kuntal1461:fix/issue-769-amount-value

Conversation

@kuntal1461

Copy link
Copy Markdown

Summary

  • Fixes GitHub issue OpenAI Java lib 4.41.0 throws OpenAIInvalidDataException in OrganizationCostsResult when parsing amount values #769: OrganizationCostsResult.Amount.value() threw OpenAIInvalidDataException when the live API returned amount.value as a quoted numeric string (e.g. "0E-6176") despite the OpenAPI spec declaring type: number
  • Root cause: Jackson's CoercionAction.Fail for String→Float caused tryDeserialize to return null for quoted numeric strings, leaving a JsonString in the JsonField which getOptional() rejected as invalid
  • Fix adds a BigDecimal fallback in Amount.value(): if asKnown() is absent and the backing field is a JsonString, parse via BigDecimalDouble with an isFinite() guard to reject overflow

Test plan

  • quoted 0E-6176 zero-cost string returns 0.0 — primary bug reproduction verified locally
  • Valid JSON number path unchanged
  • Non-numeric strings still throw OpenAIInvalidDataException
  • Overflow ("1e309") rejected by isFinite() guard
  • validate() benefits automatically (calls value() internally)

Authored-By: Kuntal maity kuntal.1461@gmail.com

…value() (openai#769)

The live API returns `OrganizationCostsResult.Amount.value` as a quoted
numeric string (e.g. "0E-6176") despite the OpenAPI spec declaring
`type: number`. Jackson's CoercionAction.Fail for String→Float causes
tryDeserialize to return null, leaving a JsonString in the JsonField
which getOptional() then rejects as invalid data.

Fix adds a BigDecimal fallback in Amount.value(): if asKnown() is absent
and the backing field is a JsonString, parse via BigDecimal → Double with
an isFinite() guard to reject overflow.

Authored-By: Kuntal maity <kuntal.1461@gmail.com>
@kuntal1461 kuntal1461 requested a review from a team as a code owner July 12, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant